#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> st;
        int i = 0;
        for (auto e : pushed)
        {
            st.push(e);
            while (st.size() && st.top() == popped[i])
            {
                st.pop();
                i++;
            }
        }
        return i == popped.size();
    }
};